'\" t
.\"     Title: fwknopd
.\"    Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.78.1 <http://docbook.sf.net/>
.\"      Date: 11/10/2015
.\"    Manual: Fwknop Server
.\"    Source: Fwknop Server
.\"  Language: English
.\"
.TH "FWKNOPD" "8" "11/10/2015" "Fwknop Server" "Fwknop Server"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.\" http://bugs.debian.org/507673
.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.\" -----------------------------------------------------------------
.\" * set default formatting
.\" -----------------------------------------------------------------
.\" disable hyphenation
.nh
.\" disable justification (adjust text to left margin only)
.ad l
.\" -----------------------------------------------------------------
.\" * MAIN CONTENT STARTS HERE *
.\" -----------------------------------------------------------------
.SH "NAME"
fwknopd \- Firewall Knock Operator Daemon
.SH "SYNOPSIS"
.sp
\fBfwknopd\fR [\fIoptions\fR]
.SH "DESCRIPTION"
.sp
\fBfwknopd\fR is the server component for the FireWall Knock Operator, and is responsible for monitoring and processing Single Packet Authorization (SPA) packets that are generated by \fBfwknop\fR clients, modifying a firewall or ACL policy to allow the desired access after authenticating and decrypting a valid SPA packet (in that order), and removing access after a configurable timeout\&.
.sp
The main application of this program is to conceal services such as \fISSH\fR with an additional layer of security in order to make the exploitation of vulnerabilities (both 0\-day and unpatched code) much more difficult\&. In addition, services that are concealed in this fashion naturally cannot be scanned for with \fINmap\fR\&.
.sp
The main configuration for \fBfwknopd\fR is maintained within two files: \fIfwknopd\&.conf\fR and \fIaccess\&.conf\fR\&. The default location for these files is determined at package configuration (typically \fI@sysconfdir@/fwknop\fR)\&. The configuration variables within these files are described below\&.
.SH "COMMAND-LINE OPTIONS"
.PP
\fB\-i, \-\-interface\fR=\fI<interface>\fR
.RS 4
Manually specify interface on which to sniff, e\&.g\&. \(lq\-i eth0\(rq\&. This option is not usually needed because the \(lqPCAP_INTF\(rq keyword in the
\fIfwknopd\&.conf\fR
file defines the sniffing interface\&.
.RE
.PP
\fB\-f, \-\-foreground\fR
.RS 4
Run
\fBfwknopd\fR
in the foreground instead of becoming a daemon\&. When run in the foreground, message that would go to the log would instead be sent to stderr\&. This mode is usually used when testing and/or debugging\&.
.RE
.PP
\fB\-\-fw\-list\fR
.RS 4
List only firewall rules that any running
\fBfwknopd\fR
daemon has created and then exit\&.
.RE
.PP
\fB\-a, \-\-access\-file\fR=\fI<access\-file>\fR
.RS 4
Specify the location of the
\fIaccess\&.conf\fR
file\&. If this option is not given,
\fIfwknopd\fR
will use the compile\-time default location (typically
\fI@sysconfdir@/fwknop/access\&.conf\fR)\&.
.RE
.PP
\fB\-c, \-\-config\fR=\fI<config\-file>\fR
.RS 4
Specify the location of the
\fIfwknopd\&.conf\fR
file\&. If this option is not given,
\fIfwknopd\fR
will use the default location (typically
\fI@sysconfdir@/fwknop/fwknopd\&.conf\fR\&.
.RE
.PP
\fB\-C, \-\-packet\-limit\fR=\fI<n>\fR
.RS 4
Specify the number of candidate SPA packets to process and exit when this limit is reached\&.
.RE
.PP
\fB\-d, \-\-digest\-file\fR=\fI<digest\-file>\fR
.RS 4
Specify the location of the
\fIdigest\&.cache\fR
file\&. If this option is not given,
\fIfwknopd\fR
will use the compile\-time default location (typically
\fI@localstatedir@/fwknop/digest\&.cache\fR)\&.
.RE
.PP
\fB\-D, \-\-dump\-config\fR
.RS 4
Dump the configuration values that
\fBfwknopd\fR
derives from the
\fI@sysconfdir@/fwknop/fwknopd\&.conf\fR
(or override files) and
\fI@sysconfdir@/fwknop/access\&.conf\fR
on stderr\&.
.RE
.PP
\fB\-\-dump\-serv\-err\-codes\fR
.RS 4
Dump all possible
\fBfwknopd\fR
error codes to stdout and exit\&. This option is rarely needed in practice, and was added to assist with test coverage\&.
.RE
.PP
\fB\-\-fault\-injection\-tag\fR=\fI<tag>\fR
.RS 4
This option is only used for fault injection testing when
\fBfwknop\fR
is compiled to support the libfiu library (see:
\fIhttp://blitiri\&.com\&.ar/p/libfiu/\fR)\&. Under normal circumstances this option is not used, and any packaged version of fwknop will not have code compiled in so this capability is not enabled at run time\&. It is documented here for completeness\&. version of fwknop will not have code compiled in to enable this capability at run time\&. It is documented here for completeness\&.
.RE
.PP
\fB\-A, \-\-afl\-fuzzing\fR
.RS 4
Instruct
\fBfwknopd\fR
to acquire SPA packets directly from stdin in support of fuzzing operations from the
\fIAmerican Fuzzy Lop\fR
(AFL) fuzzer written by Michal Zalewski\&. This requires that
\fBfwknop\fR
is compiled with the
\fI\-\-enable\-afl\-fuzzing\fR
argument to the
\fBconfigure\fR
script as this allows encryption/digest short circuiting in a manner necessary for AFL to function properly\&. The benefit of this strategy is that AFL can fuzz the SPA packet decoding routines implemented by
\fBlibfko\fR\&.
.RE
.PP
\fB\-\-fw\-list\-all\fR
.RS 4
List all firewall rules including those that have nothing to do with
\fBfwknopd\fR\&.
.RE
.PP
\fB\-\-fw\-flush\fR
.RS 4
Flush any firewall rules created by a running
\fBfwknopd\fR
process\&. This option allows the used to easily delete
\fBfwknopd\fR
firewall rules without having to wait for them to be timed out\&.
.RE
.PP
\fB\-K, \-\-kill\fR
.RS 4
Kill the current
\fBfwknopd\fR
process\&. This provides a quick and easy way to stop
\fBfwknopd\fR
without having to look in the process table\&.
.RE
.PP
\fB\-\-exit\-parse\-config\fR
.RS 4
Parse config files (\fI@sysconfdir@/fwknop/fwknopd\&.conf\fR,
\fI@sysconfdir@/fwknop/access\&.conf\fR, the digest cache file, etc\&.) and exit\&. This provides a way to test whether the config files are properly structured without having to start processing network traffic\&.
.RE
.PP
\fB\-l, \-\-locale\fR=\fI<locale>\fR
.RS 4
Set/override the system default locale setting\&.
.RE
.PP
\fB\-\-no\-ipt\-check\-support\fR
.RS 4
Disable the usage of the iptables
\fI\-C\fR
option\&. This is not normally needed, and is only useful on older Linux distributions where iptables does not have
\fI\-C\fR
support\&.
.RE
.PP
\fB\-O, \-\-override\-config\fR=\fI<file>\fR
.RS 4
Override config variable values that are normally read from the
\fI@sysconfdir@/fwknop/fwknopd\&.conf\fR
file with values from the specified file\&. Multiple override config files can be given as a comma\-separated list\&.
.RE
.PP
\fB\-\-key\-gen\fR
.RS 4
Have
\fBfwknopd\fR
generate both Rijndael and HMAC keys that can be used for SPA packet encryption and authentication\&. These keys are derived from /dev/urandom and then base64 encoded before being printed to stdout, and are meant to be manually included in a stanza within the
\fI@sysconfdir@/fwknop/access\&.conf\fR
file\&. Such keys are generally more secure than passphrases\&.
.RE
.PP
\fB\-\-key\-gen\-file\fR=\fI<file>\fR
.RS 4
Write generated keys to the specified file\&. Note that the file is overwritten if it already exists\&. If this option is not given, then
\fB\-\-key\-gen\fR
writes the keys to stdout\&.
.RE
.PP
\fB\-\-key\-len\fR=\fI<length>\fR
.RS 4
Specify the number of bytes for a generated Rijndael key\&. The maximum size is currently 128 bytes\&.
.RE
.PP
\fB\-\-hmac\-key\-len\fR=\fI<length>\fR
.RS 4
Specify the number of bytes for a generated HMAC key\&. The maximum size is currently 128 bytes\&.
.RE
.PP
\fB\-p, \-\-pid\-file\fR=\fI<pid\-file>\fR
.RS 4
Specify the location of the
\fIfwknopd\&.pid\fR
file\&. If this option is not given,
\fIfwknopd\fR
will use the compile\-time default location (typically
\fI@localstatedir@/fwknop/fwknopd\&.pid\fR)\&.
.RE
.PP
\fB\-P, \-\-pcap\-filter\fR=\fI<filter>\fR
.RS 4
Specify a Berkeley packet filter statement on the
\fBfwknopd\fR
command line\&. This overrides the value of the PCAP_FILTER variable taken from the
\fI@sysconfdir@/fwknop/fwknopd\&.conf\fR
file\&.
.RE
.PP
\fB\-\-pcap\-file\fR=\fI<pcap\-file>\fR
.RS 4
This option instructs
\fBfwknopd\fR
to read packet data from a pcap file instead of sniffing an interface directly\&. This mode is usually used for debugging purposes, and will disable SPA packet age checking unless it is manually enabled in the
\fI@sysconfdir@/fwknop/fwknopd\&.conf\fR
file\&.
.RE
.PP
\fB\-\-pcap\-any\-direction\fR
.RS 4
Allow
\fBfwknopd\fR
to sniff SPA packets regardless of whether they are received on the sniffing interface or sent from the sniffing interface\&. In the later case, this can be useful to have fwknopd sniff SPA packets that are forwarded through a system and destined for a different network\&. If the sniffing interface is the egress interface for such packets (and hence SPA packets are sent by this interface instead of received), then this option will need to used in order for
\fBfwknopd\fR
to see them\&. The default is to only sniff packets that are received on the sniffing interface\&. Note that this setting is independent of promiscuous mode\&.
.RE
.PP
\fB\-R, \-\-restart\fR
.RS 4
Restart the currently running
\fBfwknopd\fR
processes\&. This option will preserve the command line options that were supplied to the original
\fBfwknopd\fR
process but will force
\fBfwknopd\fR
to re\-read the
\fIfwknopd\&.conf\fR
and
\fI@sysconfdir@/fwknop/access\&.conf\fR
files\&. This will also force a flush of the current \(lqFWKNOP\(rq iptables chain(s)\&.
.RE
.PP
\fB\-\-rotate\-digest\-cache\fR
.RS 4
Rotate the digest cache file by renaming it to \(lq<name>\-old\(rq, and starting a new one\&. The digest cache file is typically found in
\fI@localstatedir@/fwknop/digest\&.cache\fR\&.
.RE
.PP
\fB\-r, \-\-run\-dir\fR=\fI<path>\fR
.RS 4
Specify the directory where
\fBfwknopd\fR
writes run time state files\&. The default is
\fI@localstatedir@\fR\&.
.RE
.PP
\fB\-S, \-\-status\fR
.RS 4
Display the status of any
\fBfwknopd\fR
processes that may or not be running\&. If there is an existing fwknopd process then 0 is returned for the exit status and 1 is returned otherwise\&.
.RE
.PP
\fB\-\-syslog\-enable\fR
.RS 4
Allow messages to be sent to syslog even if the foreground mode is set\&.
.RE
.PP
\fB\-t, \-\-test\fR
.RS 4
Run
\fBfwknopd\fR
in test mode\&. This instructs
\fBfwknopd\fR
to acquire and process SPA packets, but not manipulate firewall rules or execute commands that are provided by SPA clients\&. This option is mostly useful for the fuzzing tests in the test suite to ensure broad code coverage under adverse conditions\&.
.RE
.PP
\fB\-U, \-\-udp\-server\fR
.RS 4
Run
\fBfwknopd\fR
in UDP server mode so that SPA packets are acquired via a UDP socket directly without having to use libpcap\&. See the discussion of the \(lqENABLE_UDP_SERVER\(rq configuration variable below for more information\&.
.RE
.PP
\fB\-v, \-\-verbose\fR
.RS 4
Run
\fBfwknopd\fR
in verbose mode\&. This can option can be specified multiple times to increase the verbosity of the output to the system log file (or to the screen if running in the foreground)\&.
.RE
.PP
\fB\-h, \-\-help\fR
.RS 4
Display usage information and exit\&.
.RE
.PP
\fB\-V, \-\-Version\fR
.RS 4
Display version information and exit\&.
.RE
.SH "FWKNOPD CONFIG AND ACCESS VARIABLES"
.sp
\fBfwknopd\fR references the \fI@sysconfdir@/fwknop/fwknopd\&.conf\fR file for configuration variables that define its operational parameters (what network interface and port to sniff, what features to enable/disable, etc\&.)\&. The \fIfwknopd\&.conf\fR file does not define any access control directives\&.
.sp
The access control directives are contained in the \fI@sysconfdir@/fwknop/access\&.conf\fR file\&. Access control directives define encryption keys and level of access that is granted to an fwknop client that has generated the appropriate encrypted SPA message\&.
.SS "FWKNOPD\&.CONF VARIABLES"
.sp
This section list the more prominent configuration variables used by \fBfwknopd\fR\&. It is not a complete list\&. There are directives for the type of firewall used by \fBfwknopd\fR (i\&.e\&. \fIiptables\fR, \fIipfw\fR, or \fIpf\fR)\&. You will want to make sure to check these to make sure they have appropriate values\&. See the \fI@sysconfdir@/fwknop/fwknopd\&.conf\fR file for the full list and corresponding details\&.
.PP
\fBPCAP_INTF\fR \fI<interface>\fR
.RS 4
Specify the ethernet interface on which
\fBfwknopd\fR
will sniff packets\&.
.RE
.PP
\fBENABLE_PCAP_PROMISC\fR \fI<Y/N>\fR
.RS 4
By default
\fBfwknopd\fR
puts the pcap interface into promiscuous mode\&. Set this to \(lqN\(rq to disable that behavior (non\-promiscuous)\&.
.RE
.PP
\fBPCAP_FILTER\fR \fI<pcap filter spec>\fR
.RS 4
Define the filter used for
\fIPCAP\fR
modes;
\fBfwknopd\fR
defaults to UDP port 62201\&. However, if an
\fBfwknop\fR
client uses the
\fB\-\-rand\-port\fR
option to send the SPA packet over a random port, then this variable should be updated to something like \(lqudp dst portrange 10000\-65535\(rq\&.
.RE
.PP
\fBENABLE_SPA_PACKET_AGING\fR \fI<Y/N>\fR
.RS 4
This instructs
\fBfwknopd\fR
to not honor SPA packets that have an old time stamp\&. The value for \(lqold\(rq is defined by the \(lqMAX_SPA_PACKET_AGE\(rq variable\&. If \(lqENABLE_SPA_PACKET_AGING\(rq is set to \(lqN\(rq,
\fBfwknopd\fR
will not use the client time stamp at all\&.
.RE
.PP
\fBMAX_SPA_PACKET_AGE\fR \fI<seconds>\fR
.RS 4
Defines the maximum age (in seconds) that an SPA packet will be accepted\&. This requires that the client system is in relatively close time synchronization with the
\fBfwknopd\fR
server system (NTP is good)\&. The default age is 120 seconds (two minutes)\&.
.RE
.PP
\fBENABLE_DIGEST_PERSISTENCE\fR \fI<Y/N>\fR
.RS 4
Track digest sums associated with previous SPA packets processed by
\fBfwknopd\fR\&. This allows digest sums to remain persistent across executions of
\fBfwknopd\fR\&. The default is \(lqY\(rq\&. If set to \(lqN\(rq,
\fBfwknopd\fR
will not check incoming SPA packet data against any previously save digests\&. It is a good idea to leave this feature on to reduce the possibility of being vulnerable to a replay attack\&.
.RE
.PP
\fBRULES_CHECK_THRESHOLD\fR \fI<count>\fR
.RS 4
Defines the number of times firewall rule expiration times must be checked before a "deep" check is run\&. This allows
\fBfwknopd\fR
to remove rules that contain a proper
\fI\fIexp\fR\fR\fI<time>\fR
even if a third party program added them instead of
\fBfwknopd\fR\&. The default value for this variable is 20, and this typically results in this check being run every two seconds or so\&. To disable this type of checking altogether, set this variable to zero\&.
.RE
.PP
\fBENABLE_IPT_FORWARDING\fR \fI<Y/N>\fR
.RS 4
Allow SPA clients to request access to services through an iptables firewall instead of just to it (i\&.e\&. access through the FWKNOP_FORWARD chain instead of the INPUT chain)\&.
.RE
.PP
\fBENABLE_IPT_LOCAL_NAT\fR \fI<Y/N>\fR
.RS 4
Allow SPA clients to request access to a local socket via NAT\&. This still puts an ACCEPT rule into the FWKNOP_INPUT chain, but a different port is translated via DNAT rules to the real one\&. So, the user would do \(lqssh \-p <port>\(rq to access the local service (see the
\fB\-\-NAT\-local\fR
and
\fB\-\-NAT\-rand\-port\fR
on the
\fBfwknop\fR
client command line)\&.
.RE
.PP
\fBENABLE_IPT_SNAT\fR \fI<Y/N>\fR
.RS 4
Set this to \(lqY\(rq to enable a corresponding SNAT rule\&. By default, if forwarding access is enabled (see the \(lqENABLE_IPT_FORWARDING\(rq variable above), then
\fBfwknopd\fR
creates DNAT rules for incoming connections, but does not also complement these rules with SNAT rules at the same time\&. In some situations, internal systems may not have a route back out for the source address of the incoming connection, so it is necessary to also apply SNAT rules so that the internal systems see the IP of the internal interface where
\fBfwknopd\fR
is running\&.
.RE
.PP
\fBSNAT_TRANSLATE_IP\fR \fI<ip_address>\fR
.RS 4
Specify the IP address for SNAT\&. This functionality is only enabled when \(lqENABLE_IPT_SNAT\(rq is set to \(lqY\(rq and by default SNAT rules are built with the MASQUERADE target (since then the internal IP does not have to be defined here in the
\fI@sysconfdir@/fwknop/fwknopd\&.conf\fR
file), but if you want
\fBfwknopd\fR
to use the SNAT target, you must also define an IP address with the \(lqSNAT_TRANSLATE_IP\(rq variable\&. Note that this variable is generally deprecated in favor of the \(lqFORCE_SNAT\(rq variable in the
\fI@sysconfdir@/fwknop/access\&.conf\fR
file which enables per\-stanza control over the SNAT IP\&.
.RE
.PP
\fBENABLE_IPT_OUTPUT\fR \fI<Y/N>\fR
.RS 4
Add ACCEPT rules to the FWKNOP_OUTPUT chain\&. This is usually only useful if there are no state tracking rules to allow connection responses out and the OUTPUT chain has a default\-drop stance\&.
.RE
.PP
\fBMAX_SNIFF_BYTES\fR \fI<bytes>\fR
.RS 4
Specify the the maximum number of bytes to sniff per frame\&. 1500 is the default\&.
.RE
.PP
\fBFLUSH_IPT_AT_INIT\fR \fI<Y/N>\fR
.RS 4
Flush all existing rules in the fwknop chains at
\fBfwknopd\fR
start time\&. The default is \(lqY\(rq\&.
.RE
.PP
\fBFLUSH_IPT_AT_EXIT\fR \fI<Y/N>\fR
.RS 4
Flush all existing rules in the fwknop chains when
\fBfwknopd\fR
is stopped or otherwise exits cleanly\&. The default is \(lqY\(rq\&.
.RE
.PP
\fBEXIT_AT_INTF_DOWN\fR \fI<Y/N>\fR
.RS 4
When
\fBfwknopd\fR
is sniffing an interface, if the interface is administratively downed or unplugged, fwknopd will cleanly exit and an assumption is made that any process monitoring infrastructure like systemd or upstart will restart it\&. However, if fwknopd is not being monitored by systemd, upstart, or anything else, this behavior can be disabled with the \(lqEXIT_AT_INTF_DOWN\(rq variable\&. If disabled, fwknopd will try to recover when a downed interface comes back up\&.
.RE
.PP
\fBGPG_HOME_DIR\fR \fI<path>\fR
.RS 4
If GPG keys are used instead of a Rijndael symmetric key, this is the default GPG keys directory\&. Note that each access stanza in
\fI@sysconfdir@/fwknop/access\&.conf\fR
can specify its own GPG directory to override this default\&. If not set here or in an
\fIaccess\&.conf\fR
stanza, then the
\fI$HOME/\&.gnupg\fR
directory of the user running
\fBfwknopd\fR
(most likely root)\&.
.RE
.PP
\fBGPG_EXE\fR \fI<path>\fR
.RS 4
Specify the path to GPG, and defaults to
\fI/usr/bin/gpg\fR
if not set\&.
.RE
.PP
\fBLOCALE\fR \fI<locale>\fR
.RS 4
Set the locale (via the LC_ALL variable)\&. This can be set to override the default system locale\&.
.RE
.PP
\fBENABLE_SPA_OVER_HTTP\fR \fI<Y/N>\fR
.RS 4
Allow
\fBfwknopd\fR
to acquire SPA data from HTTP requests (generated with the fwknop client in
\fB\-\-HTTP\fR
mode)\&. Note that when this is enabled, the \(lqPCAP_FILTER\(rq variable would need to be updated to sniff traffic over TCP/80 connections and a web server should be running on the same server as
\fBfwknopd\fR\&.
.RE
.PP
\fBENABLE_TCP_SERVER\fR \fI<Y/N>\fR
.RS 4
Enable the fwknopd TCP server\&. This is a "dummy" TCP server that will accept TCP connection requests on the specified TCPSERV_PORT\&. If set to "Y", fwknopd will fork off a child process to listen for, and accept incoming TCP request\&. This server only accepts the request\&. It does not otherwise communicate\&. This is only to allow the incoming SPA over TCP packet which is detected via PCAP\&. The connection is closed after 1 second regardless\&. Note that fwknopd still only gets its data via pcap, so the filter defined by PCAP_FILTER needs to be updated to include this TCP port\&.
.RE
.PP
\fBTCPSERV_PORT\fR \fI<port>\fR
.RS 4
Set the port number that the \(lqdummy\(rq TCP server listens on\&. This server is only spawned when \(lqENABLE_TCP_SERVER\(rq is set to \(lqY\(rq\&.
.RE
.PP
\fBENABLE_UDP_SERVER\fR \fI<Y/N>\fR
.RS 4
Enable the
\fBfwknopd\fR
UDP server\&. This instructs
\fBfwknopd\fR
to acquire SPA packets via a UDP socket directly without having to use libpcap\&. When this mode is enabled,
\fBfwknop\fR
should be compiled with
\fB\-\-enable\-udp\-server\fR
(passed to the
\fBconfigure\fR
script) so that libpcap can be removed as a dependency\&. As one would expect, when the UDP server is used, no incoming packets are ever acknowledged by
\fBfwknopd\fR
and therefore collecting SPA packets in this mode is a good alternative to sniffing the wire directly\&.
.RE
.PP
\fBUDPSERV_PORT\fR \fI<port>\fR
.RS 4
Set the port number that the UDP server listens on\&. This server is only spawned when \(lqENABLE_UDP_SERVER\(rq is set to \(lqY\(rq\&.
.RE
.PP
\fBPCAP_DISPATCH_COUNT\fR \fI<count>\fR
.RS 4
Sets the number of packets that are processed when the
\fBpcap_dispatch()\fR
call is made\&. The default is zero, since this allows
\fBfwknopd\fR
to process as many packets as possible in the corresponding callback where the SPA handling routine is called for packets that pass a set of prerequisite checks\&. However, if
\fBfwknopd\fR
is running on a platform with an old version of libpcap, it may be necessary to change this value to a positive non\-zero integer\&. More information can be found in the
\fBpcap_dispatch(3)\fR
man page\&.
.RE
.PP
\fBPCAP_LOOP_SLEEP\fR \fI<microseconds>\fR
.RS 4
Sets the number of microseconds to passed as an argument to usleep() in the pcap loop\&. The default is 10000, or 1/10th of a second\&.
.RE
.PP
\fBENABLE_PCAP_ANY_DIRECTION\fR \fI<Y/N>\fR
.RS 4
Controls whether fwknopd is permitted to sniff SPA packets regardless of whether they are received on the sniffing interface or sent from the sniffing interface\&. In the later case, this can be useful to have fwknopd sniff SPA packets that are forwarded through a system and destined for a different network\&. If the sniffing interface is the egress interface for such packets, then this variable will need to be set to "Y" in order for fwknopd to see them\&. The default is "N" so that fwknopd only looks for SPA packets that are received on the sniffing interface (note that this is independent of promiscuous mode)\&.
.RE
.PP
\fBSYSLOG_IDENTITY\fR \fI<identity>\fR
.RS 4
Override syslog identity on message logged by
\fBfwknopd\fR\&. The defaults are usually ok\&.
.RE
.PP
\fBSYSLOG_FACILITY\fR \fI<facility>\fR
.RS 4
Override syslog facility\&. The \(lqSYSLOG_FACILITY\(rq variable can be set to
.RE
.PP
\fBENABLE_DESTINATION_RULE\fR \fI<Y/N>\fR
.RS 4
Controls whether
\fBfwknopd\fR
will set the destination field on the firewall rule to the destination address specified on the incoming SPA packet\&. This is useful for interfaces with multiple IP addresses hosting separate services\&. If \(lqENABLE_IPT_OUTPUT\(rq is set to \(lqY\(rq, the source field of the firewall rule is set\&. FORWARD and SNAT rules are not affected however, DNAT rules will also have their destination field set\&. The default is \(lqN\(rq, which sets the destination field to 0\&.0\&.0\&.0/0 (any)\&.
.RE
.PP
\fBFWKNOP_RUN_DIR\fR \fI<path>\fR
.RS 4
Specify the directory where
\fBfwknopd\fR
writes run time state files\&. The default is
\fI@localstatedir@\fR\&.
.RE
.SS "ACCESS\&.CONF VARIABLES"
.sp
This section describes the access control directives in the \fI@sysconfdir@/fwknop/access\&.conf\fR file\&. Theses directives define encryption keys and level of access that is granted to \fBfwknop\fR clients that have generated the appropriate encrypted message\&.
.sp
The \fIaccess\&.conf\fR variables described below provide the access directives for the SPA packets with a source (or embedded request) IP that matches an address or network range defined by the \(lqSOURCE\(rq variable\&. All variables following \(lqSOURCE\(rq apply to the source \fIstanza\fR\&. Each \(lqSOURCE\(rq directive starts a new stanza\&.
.PP
\fBSOURCE\fR \fI<IP,\&.\&.,IP/NET,\&.\&.,NET/ANY>\fR
.RS 4
This defines the source address from which the SPA packet will be accepted\&. The string \(lqANY\(rq is also accepted if a valid SPA packet should be honored from any source IP\&. Every authorization stanza in
\fI@sysconfdir@/fwknop/access\&.conf\fR
definition must start with the \(lqSOURCE\(rq keyword\&. Networks should be specified in CIDR notation (e\&.g\&. \(lq192\&.168\&.10\&.0/24\(rq), and individual IP addresses can be specified as well\&. Also, multiple IP\(cqs and/or networks can be defined as a comma separated list (e\&.g\&. \(lq192\&.168\&.10\&.0/24,10\&.1\&.1\&.123\(rq)
.RE
.PP
\fBDESTINATION\fR \fI<IP,\&.\&.,IP/NET,\&.\&.,NET/ANY>\fR
.RS 4
This defines the destination address for which the SPA packet will be accepted\&. The string \(lqANY\(rq is also accepted if a valid SPA packet should be honored to any destination IP\&. Networks should be specified in CIDR notation (e\&.g\&. \(lq192\&.168\&.10\&.0/24\(rq), and individual IP addresses can be specified as well\&. Also, multiple IP\(cqs and/or networks can be defined as a comma separated list (e\&.g\&. \(lq192\&.168\&.10\&.0/24,10\&.1\&.1\&.123\(rq)
.RE
.PP
\fBOPEN_PORTS\fR \fI<proto/port>,\&...,<proto/port>\fR
.RS 4
Define a set of ports and protocols (tcp or udp) that will be opened if a valid knock sequence is seen\&. If this entry is not set,
\fBfwknopd\fR
will attempt to honor any proto/port request specified in the SPA data (unless of it matches any \(lqRESTRICT_PORTS\(rq entries)\&. Multiple entries are comma\-separated\&.
.RE
.PP
\fBRESTRICT_PORTS\fR \fI<proto/port>,\&...,<proto/port>\fR
.RS 4
Define a set of ports and protocols (tcp or udp) that are explicitly
\fBnot\fR
allowed regardless of the validity of the incoming SPA packet\&. Multiple entries are comma\-separated\&.
.RE
.PP
\fBKEY\fR \fI<passphrase>\fR
.RS 4
Define the symmetric key used for decrypting an incoming SPA packet that is encrypted by the
\fBfwknop\fR
client with Rijndael\&. The actual encryption key that is used is derived from the standard PBKDF1 algorithm\&. This variable is required for all SPA packets unless GnuPG is used instead (see the GPG variables below)\&.
.RE
.PP
\fBKEY_BASE64\fR \fI<base64 encoded passphrase>\fR
.RS 4
Same as the
\fBKEY\fR
option above, but specify the symmetric key as a base64 encoded string\&. This allows non\-ascii characters to be included in the base64\-decoded key\&.
.RE
.PP
\fBHMAC_KEY\fR \fI<key>\fR
.RS 4
Specify the HMAC key for authenticated encryption of SPA packets\&. This supports both Rijndael and GPG encryption modes, and is applied according to the encrypt\-then\-authenticate model\&.
.RE
.PP
\fBHMAC_KEY_BASE64\fR \fI<base64 encoded key>\fR
.RS 4
Specify the HMAC key as a base64 encoded string\&. This allows non\-ascii characters to be included in the base64\-decoded key\&.
.RE
.PP
\fBFW_ACCESS_TIMEOUT\fR \fI<seconds>\fR
.RS 4
Define the length of time access will be granted by
\fBfwknopd\fR
through the firewall after a valid knock sequence from a source IP address\&. If \(lqFW_ACCESS_TIMEOUT\(rq is not set then the default timeout of 30 seconds will automatically be set\&.
.RE
.PP
\fBENCRYPTION_MODE\fR \fI<mode>\fR
.RS 4
Specify the encryption mode when AES is used\&. The default is CBC mode, but other modes can be selected such as OFB and CFB\&. In general, it is recommended to not use this variable and leave it as the default\&. Note that the string \(lqlegacy\(rq can be specified in order to generate SPA packets with the old initialization vector strategy used by versions of
\fBfwknop\fR
before 2\&.5\&. With the 2\&.5 release,
\fBfwknop\fR
uses PBKDF1 for key derivation\&.
.RE
.PP
\fBHMAC_DIGEST_TYPE\fR \fI<digest algorithm>\fR
.RS 4
Specify the digest algorithm for incoming SPA packet authentication\&. Must be one of
\fBMD5\fR,
\fBSHA1\fR,
\fBSHA256\fR,
\fBSHA384\fR, or
\fBSHA512\fR\&. This is an optional field, and if not specified then
\fBfwknopd\fR
defaults to using SHA256 if the access stanza requires an HMAC\&.
.RE
.PP
\fBACCESS_EXPIRE\fR \fI<MM/DD/YYYY>\fR
.RS 4
Defines an expiration date for the access stanza in MM/DD/YYYY format\&. All SPA packets that match an expired stanza will be ignored\&. This parameter is optional\&.
.RE
.PP
\fBACCESS_EXPIRE_EPOCH\fR \fI<seconds>\fR
.RS 4
Defines an expiration date for the access stanza as the epoch time, and is useful if a more accurate expiration time needs to be given than the day resolution offered by the ACCESS_EXPIRE variable above\&. All SPA packets that match an expired stanza will be ignored\&. This parameter is optional\&.
.RE
.PP
\fBENABLE_CMD_EXEC\fR \fI<Y/N>\fR
.RS 4
This instructs
\fBfwknopd\fR
to accept complete commands that are contained within an authorization packet\&. Any such command will be executed on the
\fBfwknopd\fR
server as the user specified by the \(lqCMD_EXEC_USER\(rq or as the user that started
\fBfwknopd\fR
if that is not set\&.
.RE
.PP
\fBENABLE_CMD_SUDO_EXEC\fR \fI<Y/N>\fR
.RS 4
\fBsudo\fR
provides a powerful means of restricting the sets of commands that users can execute via the \(lqsudoers\(rq file\&. By enabling this feature (and in \(lqENABLE_CMD_EXEC\(rq mode), all incoming commands from valid SPA packets will be prefixed by \(lq/path/to/sudo \-u <user> \-g <group>\(rq where the path to sudo is set by the \(lqSUDO_EXE\(rq variable, \(lq<user>\(rq is set by the \(lqCMD_SUDO_EXEC_USER\(rq variable (default is \(lqroot\(rq if not set), and \(lq<group>\(rq is set by \(lqCMD_SUDO_EXEC_GROUP\(rq (default is also \(lqroot\(rq if not set)\&.
.RE
.PP
\fBCMD_EXEC_USER\fR \fI<username>\fR
.RS 4
Specify the user (via setuid) that will execute a command contained within a SPA packet\&. If this variable is not given, fwknopd will execute the command as the user it is running as (most likely root)\&. Setting this to a non\-root user such as \(lqnobody\(rq is highly recommended if elevated permissions are not needed\&.
.RE
.PP
\fBCMD_SUDO_EXEC_USER\fR \fI<username>\fR
.RS 4
Specify the user (via \(lqsudo \-u <user>\(rq) that will execute a command contained within a SPA packet\&. If this variable is not given, fwknopd will assume the command should be executed as root\&.
.RE
.PP
\fBCMD_EXEC_GROUP\fR \fI<groupname>\fR
.RS 4
Specify the group (via setgid) that will execute a command contained within a SPA packet\&. If this variable is not given, fwknopd will execute the command as the user it is running as (most likely root)\&. Setting this to a non\-root user such as \(lqnobody\(rq is highly recommended if elevated permissions are not needed\&.
.RE
.PP
\fBCMD_SUDO_EXEC_GROUP\fR \fI<groupname>\fR
.RS 4
Specify the group (via \(lqsudo \-g <group>\(rq) that will execute a command contained within a SPA packet\&. If this variable is not given, fwknopd will assume the command should be executed as root\&.
.RE
.PP
\fBCMD_CYCLE_OPEN\fR \fI<command>\fR
.RS 4
Specify a command open/close cycle to be executed upon receipt of a valid SPA packet\&. This directive sets the initial command, and is meant to be used in conjunction with the \(lqCMD_CYCLE_CLOSE\(rq variable below\&. The main application of this feature is to allow
\fBfwknopd\fR
to interact with firewall or ACL\(cqs that are not natively supported, and facilitate the same access model as for the main supported firewalls such as iptables\&. That is, a command is executed to open the firewall or ACL, and then a corresponding close command is executed after a timer expires\&. Both the \(lqCMD_CYCLE_OPEN\(rq and \(lqCMD_CYCLE_CLOSE\(rq variables support special substitution strings to allow values to be taken from the SPA payload and used on the command line of the executed command\&. These strings begin with a \(lq$\(rq character, and include \(lq$IP\(rq (the allow IP decrypted from the SPA payload), \(lq$SRC\(rq (synonym for \(lq$IP\(rq) , \(lq$PKT_SRC\(rq (the source IP in the network layer header of the SPA packet), \(lq$DST\(rq (the destination IP), \(lq$PORT\(rq (the allow port), and \(lq$PROTO\(rq (the allow protocol)\&.
.RE
.PP
\fBCMD_CYCLE_CLOSE\fR \fI<command>\fR
.RS 4
Specify the close command that corresponds to the open command set by the \(lqCMD_CYCLE_OPEN\(rq variable described above\&. The same string substitutions such as \(lq$IP\(rq, \(lq$PORT\(rq, and \(lq$PROTO\(rq are supported\&. In addition, the special value \(lqNONE\(rq can be set to allow no close command to be executed after the open command\&. This might be handy in certain situations where, say, indefinite access is desired and allowed\&.
.RE
.PP
\fBCMD_CYCLE_TIMER\fR \fI<seconds>\fR
.RS 4
Set the number of seconds after which the close command set in \(lqCMD_CYCLE_CLOSE\(rq will be executed\&. This defines the open/close timer interval\&.
.RE
.PP
\fBSUDO_EXE\fR \fI<path>\fR
.RS 4
Define the path to the sudo binary\&. Default is \(lq/usr/bin/sudo\(rq\&.
.RE
.PP
\fBREQUIRE_USERNAME\fR \fI<username>\fR
.RS 4
Require a specific username from the client system as encoded in the SPA data\&. This variable is optional and if not specified, the username data in the SPA data is ignored\&.
.RE
.PP
\fBREQUIRE_SOURCE_ADDRESS\fR \fI<Y/N>\fR
.RS 4
Force all SPA packets to contain a real IP address within the encrypted data\&. This makes it impossible to use the
\fB\-s\fR
command line argument on the
\fBfwknop\fR
client command line, so either
\fB\-R\fR
has to be used to automatically resolve the external address (if the client behind a NAT) or the client must know the external IP and set it via the
\fB\-a\fR
argument\&.
.RE
.PP
\fBREQUIRE_SOURCE_ADDRESS\fR \fI<Y/N>\fR
.RS 4
Synonym for \(lqREQUIRE_SOURCE_ADDRESS\(rq\&.
.RE
.PP
\fBFORCE_NAT\fR \fI<IP> <PORT>\fR
.RS 4
For any valid SPA packet, force the requested connection to be NAT\(cqd through to the specified (usually internal) IP and port value\&. This is useful if there are multiple internal systems running a service such as SSHD, and you want to give transparent access to only one internal system for each stanza in the access\&.conf file\&. This way, multiple external users can each directly access only one internal system per SPA key\&.
.RE
.PP
\fBFORCE_SNAT\fR \fI<IP>\fR
.RS 4
For any valid SPA packet, add an SNAT rule in addition to any DNAT rule created with a corresponding (required) FORCE_NAT variable\&. This is analogous to \(lqSNAT_TRANSLATE_IP\(rq from the
\fI@sysconfdir@/fwknop/fwknopd\&.conf\fR
file except that it is per access stanza and overrides any value set with \(lqSNAT_TRANSLATE_IP\(rq\&. This is useful for situations where an incoming NAT\(cqd connection may be otherwise unanswerable due to routing constraints (i\&.e\&. the system receiving the SPA authenticated connection has a default route to a different device than the SPA system itself)\&.
.RE
.PP
\fBFORCE_MASQUERADE\fR \fI<Y/N>\fR
.RS 4
This is similar to the \(lqFORCE_SNAT\(rq variable, except that it is not necessary to also specify an IP address for SNAT rules because the MASQUERADE target is used instead\&.
.RE
.PP
\fBFORWARD_ALL\fR \fI<Y/N>\fR
.RS 4
In NAT scenarios, control whether all traffic is forwarded through the
\fBfwknopd\fR
system as opposed to just forwarding connections to specific services as requested by the
\fBfwknop\fR
client\&.
.RE
.PP
\fBDISABLE_DNAT\fR \fI<Y/N>\fR
.RS 4
Control whether DNAT rules are created in FORCE_NAT scenarios\&. This is mainly used in conjunction with the FORWARD_ALL variable to allow
\fBfwknopd\fR
to act essentially as an SPA gateway\&. I\&.e\&., the
\fBfwknop\fR
client is used to gain access via SPA to the broader Internet after being granted an IP via DHCP, but prior to sending the SPA packet all traffic is blocked by default to the Internet\&.
.RE
.PP
\fBGPG_DECRYPT_ID\fR \fI<keyID>\fR
.RS 4
Define a GnuPG key ID to use for decrypting SPA messages that have been encrypted by an
\fBfwknop\fR
client\&. This keyword is required for authentication that is based on GPG keys\&. The GPG key ring on the client must have imported and signed the
\fBfwknopd\fR
server key, and vice versa\&. It is ok to use a sensitive personal GPG key on the client, but each
\fBfwknopd\fR
server should have its own GPG key that is generated specifically for fwknop communications\&. The reason for this is that the decryption password for the server key must be placed within the
\fI@sysconfdir@/fwknop/access\&.conf\fR
file for
\fBfwknopd\fR
to function (it has to be able to decrypt SPA messages that have been encrypted with the server\(cqs public key)\&. For more information on using fwknop with GnuPG keys, see the following link: \(lqhttp://www\&.cipherdyne\&.org/fwknop/docs/gpghowto\&.html\(rq\&.
.RE
.PP
\fBGPG_DECRYPT_PW\fR \fI<decrypt password>\fR
.RS 4
Specify the decryption password for the gpg key defined by the \(lqGPG_DECRYPT_ID\(rq above\&. This is a required field for gpg\-based authentication\&.
.RE
.PP
\fBGPG_ALLOW_NO_PW\fR \fI<Y/N>\fR
.RS 4
Allow
\fBfwknopd\fR
to leverage a GnuPG key pair that does not have an associated password\&. While this may sound like a controversial deployment mode, in automated environments it makes sense because "there is usually no way to store a password more securely than on the secret keyring itself" according to: \(lqhttp://www\&.gnupg\&.org/faq/GnuPG\-FAQ\&.html#how\-can\-i\-use\-gnupg\-in\-an\-automated\-environment\(rq\&. Using this feature and removing the passphrase from a GnuPG key pair is useful in some environments where libgpgme is forced to use gpg\-agent and/or pinentry to collect a passphrase\&.
.RE
.PP
\fBGPG_REQUIRE_SIG\fR \fI<Y/N>\fR
.RS 4
With this setting set to
\fIY\fR, fwknopd check all GPG\-encrypted SPA messages for a signature (signed by the sender\(cqs key)\&. If the incoming message is not signed, the decryption process will fail\&. If not set, the default is
\fIY\fR\&.
.RE
.PP
\fBGPG_DISABLE_SIG\fR \fI<Y/N>\fR
.RS 4
Disable signature verification for incoming SPA messages\&. This is not a recommended setting, and the default is
\fIN\fR\&.
.RE
.PP
\fBGPG_IGNORE_SIG_VERIFY_ERROR\fR \fI<Y/N>\fR
.RS 4
Setting this will allow fwknopd to accept incoming GPG\-encrypted packets that are signed, but the signature did not pass verification (i\&.e\&. the signer key was expired, etc\&.)\&. This setting only applies if the GPG_REQUIRE_SIG is also set to
\fIY\fR\&.
.RE
.PP
\fBGPG_REMOTE_ID\fR \fI<keyID,\&...,keyID>\fR
.RS 4
Define a list of gpg key ID\(cqs that are required to have signed any incoming SPA message that has been encrypted with the
\fBfwknopd\fR
server key\&. This ensures that the verification of the remote user is accomplished via a strong cryptographic mechanism\&. Signature verification is enabled by default, and can only be disabled if \(lqGPG_DISABLE_SIG\(rq is set to
\fIY\fR
(not a recommended setting)\&. Separate multiple entries with a comma\&.
.RE
.PP
\fBGPG_FINGERPRINT_ID\fR \fI<keyID,\&...,keyID>\fR
.RS 4
Specify a set of full\-length GnuPG key fingerprints instead of the shorter key identifiers set with the \(lqGPG_REMOTE_ID\(rq variable\&. Here is an example fingerprint for one of the fwknop test suite keys:
\fI00CC95F05BC146B6AC4038C9E36F443C6A3FAD56\fR\&.
.RE
.PP
\fBGPG_HOME_DIR\fR \fI<path>\fR
.RS 4
Define the path to the GnuPG directory to be used by the
\fBfwknopd\fR
server\&. If this keyword is not specified within
\fI@sysconfdir@/fwknop/access\&.conf\fR
then
\fBfwknopd\fR
will default to using the
\fI/root/\&.gnupg\fR
directory for the server key(s) for incoming SPA packets handled by the matching
\fIaccess\&.conf\fR
stanza\&.
.RE
.PP
\fBGPG_EXE\fR \fI<path>\fR
.RS 4
Define the path to the GnuPG executable\&. If this keyword is not specified within
\fI@sysconfdir@/fwknop/access\&.conf\fR
then
\fBfwknopd\fR
will default to using
\fI/usr/bin/gpg\fR\&.
.RE
.SH "FILES"
.PP
\fB@sysconfdir@/fwknop/fwknopd\&.conf\fR
.RS 4
The main configuration file for fwknop\&.
.RE
.PP
\fB@sysconfdir@/fwknop/access\&.conf\fR
.RS 4
Defines all knock sequences and access control directives\&.
.RE
.SH "DEPENDENCIES"
.sp
\fBfwknopd\fR requires \fIlibfko\fR which is normally included with both source and binary distributions, and is a dedicated library developed by the fwknop project\&.
.sp
For packet sniffing, \fBfwknopd\fR currently requires libpcap, but future versions will (optionally) remove this as a dependency\&.
.sp
For GPG functionality, GnuPG must also be correctly installed and configured along with the libgpgme library\&.
.sp
To take advantage of all of the authentication and access management features of the \fBfwknopd\fR daemon/service a functioning iptables, ipfw, or pf firewall is required on the underlying operating system\&.
.SH "DIAGNOSTICS"
.sp
\fBfwknopd\fR can be run in debug mode by combining the \fB\-f, \-\-foreground\fR and the \fB\-v, \-\-verbose\fR command line options\&. This will disable daemon mode execution, and print verbose information to the screen on stderr as packets are received\&.
.sp
The most comprehensive way to gain diagnostic information on \fBfwknopd\fR is to run the test suite \fItest\-fwknop\&.pl\fR script located in the \fItest/\fR directory in the fwknop sources\&. The test suite runs sends fwknop through a large number of run time tests, has \fIvalgrind\fR support, validates both SPA encryption and HMAC results against OpenSSL, and even has its own built in fuzzer for SPA communications\&.
.SH "SEE ALSO"
.sp
fwknopd(8), iptables(8), pf(4), pfctl(8), ipfw(8), gpg(1), libfko documentation\&.
.sp
More information on Single Packet Authorization can be found in the paper \(lqSingle Packet Authorization with fwknop\(rq available at \fIhttp://www\&.cipherdyne\&.org/fwknop/docs/SPA\&.html\fR\&. A comprehensive tutorial on \fBfwknop\fR operations and theory can be found at \fIhttp://www\&.cipherdyne\&.org/fwknop/docs/fwknop\-tutorial\&.html\fR\&. This tutorial also includes information about the design of \fBfwknop\fR that may be worth reading for those interested in why fwknop is different from other SPA implementations\&.
.sp
\fBfwknop\fR uses the \fIgit\fR versioning system as its source code repository along with \fIGithub\fR for tracking of issues and milestones:
.sp
.if n \{\
.RS 4
.\}
.nf
    $ git clone https://github\&.com/mrash/fwknop\&.git fwknop\&.git
.fi
.if n \{\
.RE
.\}
.sp
Additional commentary on Single Packet Authorization can be found via Michael Rash\(cqs Twitter feed: http://twitter\&.com/michaelrash, @michaelrash
.SH "AUTHORS"
.sp
Damien Stuart <dstuart@dstuart\&.org>, Michael Rash <mbr@cipherdyne\&.org>
.SH "CONTRIBUTORS"
.sp
This \(lqC\(rq version of fwknop was derived from the original Perl\-based version on which many people who are active in the open source community have contributed\&. See the CREDITS file in the fwknop sources, or visit \fIhttps://github\&.com/mrash/fwknop/blob/master/CREDITS\fR to view the online list of contributors\&. A few contributors deserve to be singled out including: Franck Joncourt, Max Kastanas, Vlad Glagolev, Sean Greven, Hank Leininger, Fernando Arnaboldi, and Erik Gomez\&.
.sp
The phrase \(lqSingle Packet Authorization\(rq was coined by MadHat and Simple Nomad at the BlackHat Briefings of 2005\&.
.SH "BUGS"
.sp
Send bug reports to dstuart@dstuart\&.org or mbr@cipherdyne\&.org, or open a new issue on Github (see \fIhttps://github\&.com/mrash/fwknop\&.git\fR)\&. Suggestions and/or comments are always welcome as well\&. Additional information may be found in the \fBfwknop\fR mailing list archives (see: \fIhttps://lists\&.sourceforge\&.net/lists/listinfo/fwknop\-discuss\fR)\&.
.SH "DISTRIBUTION"
.sp
\fBfwknopd\fR is distributed under the GNU General Public License (GPL), and the latest version may be downloaded from \fIhttp://www\&.cipherdyne\&.org\fR\&.
